package queuestack;

import java.util.Stack;

public class LeetCode_232 {
    public static void main(String[] args) {
        MyQueue myQueue = new MyQueue();
        myQueue.push(1);
        myQueue.push(2);
        System.out.println(myQueue.peek());
        System.out.println(myQueue.pop());
    }
    static class MyQueue {
        private Stack<Integer> inStack;
        private Stack<Integer> outStack;
        public MyQueue() {
            inStack = new Stack<>();
            outStack = new Stack<>();
        }

        public void push(int x) {
            inStack.push(x);
        }

        public int pop() {
            if(outStack.empty()) {
                while (!inStack.empty()){
                    outStack.push(inStack.pop());
                }
            };
            return outStack.pop();
        }

        public int peek() {
            if(outStack.empty()){
                while (!inStack.empty()){
                    outStack.push(inStack.pop());
                }
            };
            return outStack.peek();
        }

        public boolean empty() {
            if (inStack.empty() && outStack.empty()) return true;
            return false;
        }
    }
}
